﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.ajax({
            url: "../data/system.aspx?method=101",
            async: false,
            success: function (text) {
                if (text == "no")
                    window.location = "error.html";
                else if (text == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    var tabs = parent.mini.get("mainTabs");
                    var tab = tabs.getTab("tab$101");
                    tabs.removeTab(tab);
                }
            }
        });
        var State = [{ id: 1, text: '启用' }, { id: 0, text: '禁用'}];
        var StateAll = [{ id: 1, text: '启用' }, { id: 0, text: '禁用' }, { id: -1, text: '全部'}];
        var StateShow = [{ id: 1, text: '<font color="Green">启用</font>' }, { id: 0, text: '<font color="Red">禁用</font>'}];
        var AdType = [{ id: 0, text: '无' }, { id: 1, text: '资讯左侧图片广告' }, { id: 2, text: 'LOGO条右侧广告' }, { id: 3, text: '导航条下侧通栏广告' }, { id: 4, text: '搜索栏下侧通栏广告' }, { id: 5, text: 'VIP招聘下侧通栏广告' }, { id: 6, text: '左右两侧挂边广告'}];
    </script>
</head>
<body>
    <div class="mini-toolbar" style="border-bottom: 0;">
        <table>
            <tr>
                <td>
                    名称：
                    <input class="mini-textbox" id="key" emptytext="关键字" />
                    状态：
                    <input id="state" class="mini-combobox" style="width: 60px;" data="StateAll" value="1"/>
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="search();">查询</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-add" plain="true" onclick="addRow();">新增</a>
                    <a class="mini-button" iconcls="icon-remove" plain="true" onclick="delRows()">删除</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-lock" plain="true" onclick="lockRows(0);">禁用</a>
                    <a class="mini-button" iconcls="icon-unlock" plain="true" onclick="lockRows(1)">启用</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit" >
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" allowresize="true"
            idfield="id" multiselect="true" url="../data/system.aspx?method=GetLevelList" sizeList="[15,20,50,100]" pageSize="15">
            <div property="columns">
                <div type="checkcolumn">
                </div>
                <div cellCls="actionIcons" name="action" width="60px" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
                <div field="cl_id" width="100px" headeralign="center" align="center" allowsort="true">
                    编号</div>
                <div field="cl_name" headeralign="center" align="center" allowsort="true">
                    名称</div>
                <div field="cl_state" width="50px" headeralign="center" align="center" allowsort="true" renderer="onStateRenderer">
                    状态</div>
                <div field="cl_ad" width="100px" headeralign="center" align="center" allowsort="true" renderer="onAdRenderer">
                    广告位</div>
                <div field="cl_recruit" width="100px" headeralign="center" align="center" allowsort="true">
                    招聘职位上限</div>
                <div field="cl_message" width="100px" headeralign="center" align="center" allowsort="true">
                    短信上限</div>
            </div>
        </div>
    </div>
    <div id="editWindow" class="mini-window" title="会员等级信息" style="width: 300px;" showmodal="true"
        allowresize="false" allowdrag="true" showFooter="true">
        <div id="editform" class="form">
            <input class="mini-hidden" name="cl_no"/>
            <table style="width: 98%; height: 100%;">
                <tr style="height: 20px">
                    <td class="tdtitle" style="width: 40%;">
                        <span class="red">*</span>编号：
                    </td>
                    <td class="tdtext">
                        <input name="cl_id" class="mini-textbox" required="true" style="width:150px;"/>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>名称：
                    </td>
                    <td class="tdtext">
                        <input name="cl_name" class="mini-textbox" required="true" style="width:150px;"/>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>广告位：
                    </td>
                    <td class="tdtext">
                        <input name="cl_ad" class="mini-combobox" repeatlayout="table" repeatdirection="vertical"
                            style="width:150px;" data="AdType" required="true" value="0" />
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>招聘职位上限：
                    </td>
                    <td class="tdtext">
                        <input name="cl_recruit" class="mini-textbox" required="true" style="width:150px;" vtype="int"/>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>短信上限：
                    </td>
                    <td class="tdtext">
                        <input name="cl_message" class="mini-textbox" required="true" style="width:150px;" vtype="int"/>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>状态：
                    </td>
                    <td class="tdtext">
                        <input name="cl_state" class="mini-radiobuttonlist" repeatlayout="table" repeatdirection="vertical"
                            data="State" value="1" required="true" />
                    </td>
                </tr>
            </table>
        </div>
        <div property="footer" style="text-align:center;padding:5px;">
            <a class="mini-button" style="width:60px;" onclick="updateRow()">保存</a>
            <span style="display:inline-block;width:25px;"></span>
            <a class="mini-button" style="width:60px;" onclick="closewin()">关闭</a>
        </div>
    </div>
    <script type="text/javascript">
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                if (XMLHttpRequest.responseText == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                }
            }
        });

        mini.parse();

        var grid = mini.get("datagrid1");
        search();

        function search() {
            var state = mini.get("state").getValue();
            var key = mini.get("key").getValue();
            grid.load({ key: key, state: state });
            grid.sortBy("cl_no", "desc");
        }

        function onStateRenderer(e) {
            for (var i = 0; i < StateShow.length; i++) {
                var s = StateShow[i];
                if (s.id == e.value)
                    return s.text;
            }
            return "";
        }

        function onAdRenderer(e) {
            for (var i = 0; i < AdType.length; i++) {
                var a = AdType[i];
                if (a.id == e.value)
                    return a.text;
            }
            return "";
        }

        function addRow() {
            var form = new mini.Form("#editform");
            form.reset();
            var win = mini.get("editWindow");
            win.setTitle("新增会员等级<span class='red'>( 带 * 号的必须填写)</span>");
            if (!win.visible)
                win.show();
        }

        function editRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                var win = mini.get("editWindow");
                var form = new mini.Form("#editform");
                form.clear();
                form.loading();
                $.ajax({
                    url: "../data/system.aspx?method=GetLevel",
                    data: { id: row.cl_no },
                    success: function (text) {
                        form.unmask();
                        if (text == "out") {
                            win.hide();
                            var loginWindow = parent.mini.get("loginWindow");
                            if (!loginWindow.visible)
                                loginWindow.show();
                            return;
                        }
                        var o = mini.decode(text);
                        form.setData(o);
                        win.setTitle("编辑会员等级<span class='red'>( 带 * 号的必须填写)</span>");
                        win.show();
                    },
                    error: function () {
                        form.unmask();
                        ShowMessage("系统提示", "信息加载出错！", 3);
                    }
                });
            }
        }

        function updateRow() {
            var form = new mini.Form("#editform");
            form.validate();
            if (form.isValid() == false)
                return;
            var o = form.getData();
            var editWindow = mini.get("editWindow");
            var json = mini.encode(o);
            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });

            $.ajax({
                url: "../data/system.aspx?method=SaveLevel",
                data: { data: json },
                success: function (ret) {
                    mini.unmask(document.body);
                    if (ret == "out") {
                        var loginWindow = parent.mini.get("loginWindow");
                        if (!loginWindow.visible)
                            loginWindow.show();
                        return;
                    }
                    if (ret == 1) {
                        editWindow.hide();
                        ShowMessage("系统提示", "会员等级保存成功！", 1);
                        grid.reload();
                    }
                    else if (ret == 0) {
                        editWindow.hide();
                        ShowMessage("系统提示", "该会员等级已不存在，请确认！", 2);
                        grid.reload();
                    }
                    else if (ret == 2) {
                        ShowMessage("系统提示", "该会员等级或编号已存在，请确认！", 2);
                    }
                    else
                        ShowMessage("系统提示", "会员等级保存失败！", 3);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    mini.unmask(document.body);
                    ShowMessage("系统提示", "会员等级保存失败！", 3);
                }
            });
        }

        function closewin() {
            var win = mini.get("editWindow");
            win.hide();
        }

        function delRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                mini.confirm("确定删除此会员等级吗？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            $.ajax({
                                url: "../data/system.aspx?method=DeleteLevel",
                                type: "post",
                                data: { id: row.cl_no },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "会员等级删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "会员等级删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "会员等级删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
        }

        function delRows() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                mini.confirm("确定删除所选会员等级吗？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].cl_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=DeleteLevel",
                                type: "post",
                                data: { id: ids },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "会员等级删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "会员等级删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "会员等级删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            } else
                    ShowMessage("系统提示", "请选择需要删除的会员等级！", 2);
        }

        function lockRows(state) {
            var rows = grid.getSelecteds();
            var msg = "启用";
            if (state == 0)
                msg = "禁用";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选会员等级吗？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '操作中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].cl_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=LockLevel",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "会员等级" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "会员等级" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "会员等级" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            } else
                ShowMessage("系统提示", "请选择需要" + msg + "的会员等级！", 2);
        }
    </script>
</body>
</html>